import { createStore } from "vuex";
import createPersistedState from "vuex-persistedstate";

const moduleFiles = import.meta.globEager("./**/*.ts");
let modules = Object.keys(moduleFiles).reduce((modules:any, route:string) => {
  let name:string|undefined = route.split('/').pop()
  if(name){
    modules[name.replace('.ts','')] = moduleFiles[route].default
  }
  return modules
}, {})

const store:any = createStore({
  modules,
  plugins: [
    createPersistedState({
      key:'merchant-vuex',
      storage: window.localStorage,
    }),
  ],
});

export default store;
